package graduation.project.testcase.strategy;

import graduation.project.body.OriginExpression;
import graduation.project.body.TestCase;
import graduation.project.body.TestCases;
import graduation.project.exception.NonExpressionException;
import graduation.project.utilities.Utility;

import java.util.ArrayList;

public class MANYBGenerator implements TestSetGenerator {

	public TestCases generateTestCases(String expression, int testCaseNumber) {
		try {
			OriginExpression originEx;
			originEx = new OriginExpression(expression);
			return generateTestCases(originEx, testCaseNumber);
		} catch (NonExpressionException e) {
			System.out.println("the expression is not valid boolean expression");
			e.printStackTrace();
		}
		return null;
	}

	public TestCases generateTestCases(OriginExpression expression,
			int testCaseNumber) {
		
		TestCases result = new TestCases(expression.getExpression(), expression.getModel(), "MANYB");
		TestCases manyA = new MANYAGenerator().generateTestCases(expression, testCaseNumber);
		ArrayList<TestCase> records = manyA.getTestSet();
		
		int[] otpSet = Utility.getSubLogArray(expression.getOtpSet());
		int[] rfpSet = Utility.getSubLogArray(expression.getRfpSet());
		
		if(otpSet != null)
			for(int i = 0; i < otpSet.length; i++)
				records.add(new TestCase(otpSet[i], true));
		
		if(rfpSet != null)
			for(int i = 0; i < rfpSet.length; i++)
				records.add(new TestCase(rfpSet[i], false));
		
		result.setTestSet(records);
		return result;
	}

}
